<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>switch demo</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="/static/css/oksub.css">
</head>
<body>
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
      <legend>Layui switch演示</legend>
    </fieldset>

    <form class="layui-form">
        <div class="layui-form-item">
            <label class="layui-form-label">状态</label>
            <div class="layui-input-block">
                <input type="checkbox" name="status" value="1" lay-skin="switch" lay-filter="switchTest" checked="checked" lay-text="正常|关闭">
            </div>
        </div>
    </form>

    <script src="/static/lib/layui/layui.js" charset="utf-8"></script>
    <script>
	// 状态监听开关
        layui.use(['form'], function () {
            var form = layui.form
                , layer = layui.layer;
            //监听指定开关
            form.on('switch(switchTest)', function (data) {
                if (this.checked) {
                    layer.msg('开关checked：' + (this.checked ? 'true' : 'false'), {
                        offset: '6px'
                    });
                    //layer.tips('温馨提示：请注意开关状态的文字可以随意定义，而不仅 仅是ON|OFF', data.othis)
                } else {
                    layer.msg('开关： 关掉了', {
                        offset: '6px'
                    });
                }
                //do some ajax opeartiopns;
            });
        });
</script>
</body>
</html>